package per.jdz.demo.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import per.jdz.demo.config.FilePathConfigProperty;
import per.jdz.demo.domain.entity.OriginHouseData;
import per.jdz.demo.domain.vo.reponse.ApiResult;
import per.jdz.demo.readlistener.GenericReadListener;
import per.jdz.demo.service.HouseDataService;
import per.jdz.demo.service.OriginHouseDataService;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.concurrent.CompletableFuture;

/**
 * @author Jdz
 * @date 2025/1/14
 */
@RestController
@Slf4j
@RequestMapping("/origin/newHouse")
public class OriginHouseDataController {
    @Resource
    private OriginHouseDataService originHouseDataService;

    @Resource
    private HouseDataService houseDataService;

    @PostMapping("/insertData")
    public ApiResult insertData() {
        originHouseDataService.insertData(originHouseDataService::saveBatch);
        return ApiResult.success();
    }

    @GetMapping("/splitFile")
    public ApiResult splitFile() {
        String msg = originHouseDataService.splitFile();
        return ApiResult.success(msg);
    }

    @GetMapping("/distinctData")
    public ApiResult distinctData() {
        log.info("开始去重");
        originHouseDataService.distinctData();
        return ApiResult.success();
    }

    @GetMapping("/syncData")
    public ApiResult syncData() {
        log.info("开始同步数据");
        originHouseDataService.syncData();
        // 对HouseData进行格式化
        houseDataService.formatRoomNumber();
        return ApiResult.success();
    }

    @GetMapping("/rename")
    public ApiResult rename() {
        log.info("开始重命名");
        originHouseDataService.rename();
        return ApiResult.success();
    }

    @GetMapping("/matchCommonId")
    public ApiResult matchCommonId() {
        log.info("开始匹配commonId");
        originHouseDataService.matchCommonId();
        return ApiResult.success();
    }

    @GetMapping("/updateHouseDataByRenameData")
    public ApiResult updateHouseDataByRenameData() {
        log.info("开始更新数据");
        originHouseDataService.updateHouseDataByRenameData();
        return ApiResult.success();
    }

    @PostMapping("/addNewData")
    public ApiResult addNewData(@RequestBody List<OriginHouseData> originHouseDataList) {
        log.info("爬取数据入库");
//        originHouseDataService.saveBatch(originHouseDataList);
        System.out.println(originHouseDataList);
        return ApiResult.success();
    }

}
